
package logic.forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm extends ActionForm {
	private static final long serialVersionUID = 1L;
	
	private String userName = null;
	private String password = null;
	
	public LoginForm() {
		super();
		this.userName = "";
		this.password = "";
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getPassword() {
		return password;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (getUserName() == null || getUserName().isEmpty()) {
			errors.add("userName",new ActionMessage("login.error.userName.empty"));
		}
		
		if (getPassword() == null || getPassword().isEmpty()) {
			errors.add("password",new ActionMessage("login.error.password.empty"));
		}
		
		return errors;
	}
}
